#include <stdio.h>
#include <stdlib.h>                                      // malloc() 需要 stdlib.h 库
#include "../../include/type_list.h"

//线性表的打印
void ListPrint_sq(Sqlist & L){
    printf("L.elem = ");
    int i;
    for (i = 0;i < L.length;i ++){
        printf("%d",L.elem[i]);
        if(i != L.length - 1){
            printf(",");
        }
    }
    printf("\n");
    printf("length = %d , listsize = %d \n", L.length, L.listsize);
    printf("\n");
}

//是否线性表内存
void freeMemory(Sqlist & L){
    free(L.elem);
}

//打印链表
void ListPrint_L(LinkList & L){
    LinkList p = L; //这里不能用引用 LinkList & p，否则后边 p = p -> next; 也会导致 L 的值发生改变!!
    int i = 0;
    while(p -> next){
        p = p -> next;
        ++i;
        printf("The ordinal num = %d  data is: %d \n",i,p -> data);
    }
}

//释放列表
void free_L(LinkList & L){
    LinkList p = L;
    while(p -> next){
        LinkList temp = p -> next;
        free(p);
        p = temp;
    }
}